package com.qfmy.webapp.service.impl.wallpaper;

import com.qfmy.model.entity.wallpaper.Emoji;
import com.qfmy.model.vo.wallpaper.EmojiVo;
import com.qfmy.webapp.mapper.wallpaper.EmojiMapper;
import com.qfmy.webapp.service.wallpaper.EmojiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author 清风明月
 * @Package com.qfmy.web.app.service.impl.wallpaper
 * @date 2025/11/26
 * @description 表情
 */
@Service
@SuppressWarnings("all")
public class EmojiServiceImpl implements EmojiService {

    /**
     * 注入mapper
     */
    @Autowired
    private EmojiMapper emojiMapper;

    /**
     * 注入redisTemplate
     */
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 获取精选表情
     * @return
     */
    @Override
    public List<EmojiVo> getJingXuanEmojis() {
        //查询数据库
        List<Emoji> emojiList = emojiMapper.getJingXuanEmojis();
        //转换为vo
        return emojiList.stream().map(emoji -> new EmojiVo(emoji.getId(), emoji.getImageUrl())).toList();
    }

    /**
     * 更新下载次数
     * @param id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateDownloadCount(Integer id) {
        emojiMapper.updateDownloadCount(id);
    }
}
